
import 'package:xsdk_flutter/xsdk/utils/json/x_utils_json.dart';
import 'package:xsdk_flutter/xsdk/xsdk_flutter_package.dart';
import 'package:xsdk_flutter_plugin/plugin/x_method_channel.dart';
import 'package:xsdk_flutter_plugin/plugin/base/xsdk_platform_interface.dart';

typedef XNativeCallback = void Function(String json);
/*
对外使用

开发时,需在x_method_channel.dart中实现功能方法,
使用时(对外):通过此工具类中调用(遵从规则通过XFlutterPluginPlatform.instance实例调用?)

 */
abstract class XFlutterPluginUtils {

  static Future<String?> getPlatformVersion() {
    return XFlutterPluginPlatform.instance.getPlatformVersion();
  }


  ////////////////////////////////////////////////////
  /*
  1.设置接收原生通知回调(null为取消)
  注意:在新界面设置接收器,这会替换旧界面的接收器,返回旧界面时要重新设置
   */
  static void setReceiveNativeMessageCallback(XFunctionResultCallback? callback){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).setReceiveNativeMessageCallback(callback);
  }


  //Android /////////////////////////////////////////////////////

  //支付宝碰一碰设备(支付,会员),初始化
  static void initAlipayIotSDK(String json){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).initAlipayIotSDK(json);
  }
  //支付宝碰一碰设备,发起普通支付,显示金额
  static void commonPayAlipayIotSDK(String json){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).commonPayAlipayIotSDK(json);
  }
  //支付宝碰一碰设备,发起会员支付
  static void memberPayAlipayIotSDK(String json){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).memberPayAlipayIotSDK(json);
  }
  //支付宝碰一碰设备,发起会员开卡
  static void memberCardAlipayIotSDK(String json){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).memberCardAlipayIotSDK(json);
  }
  //支付宝碰一碰设备,通用方法
  static void alipayIotSDK_x(String json){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).alipayIotSDK_x(json);
  }

  /////////////////////////////////

  //4线串口连接 商米机
  static void serialPortConnect(String deviceType){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).serialPortConnect(deviceType);
  }

  //手动加载.so文件,适用android6.0, so文件名称(不包括.so后续),如: objectbox-jni
  static void manualSystemLoadLibrary(String soName){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).manualSystemLoadLibrary(soName);
  }
  //Android 商米机
  static void initShangMiSDK(){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).initShangMiSDK();
  }
  static void openDrawerByShangMi(){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).openDrawerByShangMi();
  }
  static void cutPaperByShangMi(){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).cutPaperByShangMi();
  }
  static void printMsgByShangMi(String msg){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).printMsgByShangMi(msg);
  }
  static void printBytesByShangMi(List<int> bytes){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).printBytesByShangMi(bytes);
  }


  //打开第二屏幕 分屏
  static void openSecondScreen(String webUrl){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).openSecondScreen(webUrl);
  }
  //刷新第二屏幕 分屏
  static void updateSecondScreen(){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).updateSecondScreen();
  }
  //发送消息到第二屏幕 分屏
  static void sendMsgToSecondScreen(String json){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).sendMsgToSecondScreen(json);
  }

  //返回系统桌面
  static void goBackToScreen(){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).goBackToScreen();
  }
  //安装apk权限
  static void checkInstallPermission(){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).checkInstallPermission();
  }
  //FOREGROUND_SERVICE权限
  static void checkFOREGROUND_SERVICEPermission(){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).checkFOREGROUND_SERVICEPermission();
  }

  //发广播
  static void sendBroadcast(String json){
    (XFlutterPluginPlatform.instance as XFlutterPluginMethodChannel).sendBroadcast(json);
  }

  //打开钱箱(发广播方式),适配中崎一体收银机
  static void openDrawer(){
    //
    Map<String,dynamic> dMap={};
    dMap['cashbox_open']=true;
    //
    Map<String,dynamic> openDrawerMap={};
    openDrawerMap['action']='android.intent.action.CASHBOX';
    openDrawerMap['mapData']=dMap;
    sendBroadcast(XJsonUtils.obj2Json(openDrawerMap));
  }


}
